// PasswordUtils.java
package com.ruoyi.common.utils;

import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

/**
 * 密码工具类
 * @author zhouyihao
 */
@Component
public class PasswordUtils {

    /**
     * 加密密码
     */
    public String encryptPassword(String password) {
        return DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * 验证密码
     */
    public boolean matches(String rawPassword, String encodedPassword) {
        return encodedPassword.equals(encryptPassword(rawPassword));
    }
}